Assignment TWO: Fun with Filters and Frequencies

SYDE 671, Assignment 2 — Muhammad Farooq Memon

Project Overview: In this assignment, I explored the dual spatial-frequency nature of images. Part 1 builds fundamental edge and gradient detectors from scratch—diving deep into vectorized 2D convolutions, finite differences, and Derivative-of-Gaussian (DoG) filtering. Part 2 applies frequency manipulation to sharpen photos, construct multi-distance optical illusions (Hybrid Images), and blend images seamlessly using full-resolution Gaussian and Laplacian stacks.

PART 2: Applications

2.1 Image "Sharpening" (Unsharp Masking)

Image sharpening amplifies high spatial frequencies using the unsharp mask equation: \(I_{\text{sharp}} = I + \alpha (I - I * G)\), where \((I - I * G)\) isolates high-frequency details (by subtracting the blurred image from its original non-blurred form). I tested this on the Taj Mahal and custom test images across varying values of \(\alpha\).

Taj mahal original

Figure 1a. Original image of Taj Mahal

Taj mahal sharpened 1.0

Figure 1b. Image of Taj Mahal sharpened α = 1.0

Taj mahal sharpened 1.5

Figure 1c. Image of Taj Mahal sharpened α = 1.5

Taj mahal sharpened 2.0

Figure 1d. Image of Taj Mahal sharpened α = 2.0

Taj mahal sharpened 5.0

Figure 1e. Image of Taj Mahal sharpened α = 5.0

Road original

Figure 1f. Original image of road

Road sharpened 1.0

Figure 1g. Image of road sharpened α = 1.0

Road sharpened 1.5

Figure 1h. Image of road sharpened α = 1.5

Evaluation Experiment: Sharp → Blur → Re-sharpen

Bird original

Figure 1i. Original image of bird

Road blurred

Figure 1j. Blurred image of the bird Blurred (G * I)

bird sharpened 2.0

Figure 1k. Image of bird re-sharpened α = 2.0

Bird sharpened 10

Figure 1l. Original image of bird sharpened α = 10.0

Evaluation & Color Troubleshooting Insights:

2.2 Hybrid Images & Frequency Analysis

Hybrid images (Oliva, Torralba & Schyns, SIGGRAPH 2006) combine the low spatial frequencies of Image A with the high spatial frequencies of Image B. When viewed up close, high frequencies dominate human perception however, from a distance, high frequencies blend away and low frequencies take over.

I built alignment tools using similarity transforms based on clicked eye coordinates and tested 3 pairs: Derek + Nutmeg (given in assignment), football players Cristiano Ronaldo + Mohammed Salah, and main characters of the Netflix series: Saul Goodman from Better Call Saul and Walter White from Breaking Bad.

Full 5-Stage Fourier Transform Pipeline (BBCS: Saul Goodman + Walter White)

Below is the 2D Fourier log-magnitude spectrum (np.log(np.abs(np.fft.fftshift(np.fft.fft2(img))))) tracked across every stage of the hybrid pipeline:

Saul Goodman original image

Figure 2a. Saul Goodman original image

Walter White original Image

Figure 2b. Walter White original Image

Low pass filter on Saul

Figure 2c. Low pass filter on Saul

High pass filter on Walter White

Figure 2d. High pass filter on Walter White

Result

Figure 2e. Hybrid result

Fourier transformation stages

Figure 2f. 2D Fourier log-magnitude spectrum

FFT Spectrum Analysis:

Additional Hybrid Results

Derek and Cat image

Figure 2g. Derek and Cat hybrid

Cristiano Ronaldo and Mohammed Salah (Footballers)

Figure 2h. Cristiano Ronaldo and Mohammed Salah (Footballers)

Bells & Whistles (Part 2): Color Mode Strategy Comparison

I evaluated three color configurations for hybrid generation: color_mode='low', color_mode='high', and color_mode='both'.

Color on Low-Pass Only

Figure 2i. Color on Low-Pass Only

Color on High-Pass Only

Figure 2j. Color on High-Pass Only

Color on Both Components

Figure 2k. Color on Both Components

Color Justification: Applying color only to the low-frequency component (color_mode='low') produces the best perceptual result. Human vision perceives broad color saturation in low spatial frequencies, whereas high-frequency color introduces chromatic noise that disrupts the perceptual grouping at distance. Color on low-pass blends naturally without giving away the high-frequency illusion up close. From the images above we can see that coloring the low frequency and both high and low frequency images yields same result. So for the good of the computation power I would say applying color to low-frequency component is sufficient.

2.3 & 2.4 Gaussian & Laplacian Stacks & Multiresolution Blending

Unlike pyramids, stacks do NOT perform downsampling. In stacks, every level retains full \(H \times W\) resolution. A Gaussian stack applies progressively larger Gaussians (\(\sigma = 1, 2, 4, 8, 16, 32 \dots\)), and the Laplacian stack computes difference layers \(L_i = G_i - G_{i+1}\), with the coarsest level \(L_{N-1} = G_{N-1}\).

Multiresolution blending (Burt & Adelson 1983, p. 230) blends each Laplacian level using the Gaussian stack of a binary mask \(G_{\text{mask}}\):

\[L_{\text{blend}}[i] = G_{\text{mask}}[i] \cdot L_A[i] + (1 - G_{\text{mask}}[i]) \cdot L_B[i]\]

Szeliski Fig 3.42 / Burt & Adelson Fig 10 (Apple + Orange "Oraple" 4x3 Grid)

Apple Laplacian stack at level 0 showing high-frequency fine edge details

Figure 3a. Level 0: Apple Laplacian High Frequencies

Orange Laplacian stack at level 0 showing high-frequency skin texture details

Figure 3b. Level 0: Orange Laplacian High Frequencies

Blended result at level 0 combining high frequencies of apple and orange

Figure 3c. Level 0: Blended High Frequencies

Apple Laplacian stack at level 1 showing fine structural features

Figure 3d. Level 1: Apple Laplacian Bandpass

Orange Laplacian stack at level 1 showing fine structural features

Figure 3e. Level 1: Orange Laplacian Bandpass

Blended result at level 1 combining mid-high bandpass frequencies

Figure 3f. Level 1: Blended Bandpass

Apple Laplacian stack at level 2 showing medium scale spatial structures

Figure 3g. Level 2: Apple Laplacian Medium Scale

Orange Laplacian stack at level 2 showing medium scale spatial structures

Figure 3h. Level 2: Orange Laplacian Medium Scale

Blended result at level 2 combining medium scale bandpass frequencies

Figure 3i. Level 2: Blended Medium Scale

Apple Laplacian stack at level 3 showing coarse low-frequency base illumination

Figure 3j. Level 3: Apple Coarse Base Component

Orange Laplacian stack at level 3 showing coarse low-frequency base illumination

Figure 3k. Level 3: Orange Coarse Base Component

Blended result at level 3 showing smooth low-frequency transition across seam

Figure 3l. Level 3: Blended Base Component

Apple Laplacian stack at level 4 showing coarse low-frequency base illumination

Figure 3m. Level 4: Apple Coarse Base Component

Orange Laplacian stack at level 4 showing coarse low-frequency base illumination

Figure 3n. Level 4: Orange Coarse Base Component

Blended result at level 4 showing smooth low-frequency transition across seam

Figure 3o. Level 4: Blended Base Component

Stack Performance Note:
Running a 6-level full-resolution stack required 2 minutes 39 seconds

Final blended Oraple result generated using a 6-level Laplacian stack showing a smooth transition seam

Figure 3p. 6-Level Laplacian Stack Blend (σ0 = 1.0)

Final blended Oraple result generated using a 7-level Laplacian stack with wider low-frequency transition width

Figure 3q. 7-Level Laplacian Stack Blend (σ0 = 1.0)

, while a 7-level stack took over 14 minutes due to expanding \(6\sigma\) kernel convolutions! However, 6 levels with \(\sigma_0=1.0\) (max \(\sigma=32\)) provided an optimal transition width across the center seam.

Custom Blends with Straight and Irregular Masks

Cheetah Original picture

Figure 3r. Cheetah original image

Lion Original picture

Figure 3s. Lion original image

Mask

Figure 3t. Mask is vertical

Blended lion and cheetah

Figure 3t. Cheetah + Lion = Cheeion

Original grayscale image of a human eye

Figure 3u. Eye Original Image

Original image of planet Earth from space

Figure 3v. Earth Original Image

Irregular binarized mask separating the pupil and iris geometry from the eye

Figure 3w. Irregular Binarized Mask (Threshold = 0.4)

Final multiresolution composite blending planet Earth seamlessly into the human eye iris

Figure 3x. Eye + Earth = Earth Eye Composite

Original photo of a man

Figure 3y. Man Original Image

Original photo of a broccoli head

Figure 3z. Broccoli Original Image

Custom binarized threshold mask isolating the target region

Figure 3aa. Custom Binarized Threshold Mask (Threshold = 0.4)

Final multiresolution composite seamlessly blending broccoli head onto the man

Figure 3ab. Man + Broccoli = Brocco-Man Composite

Bells and Whistles

Mask Choice & Color Justification for Blending: For the Eye + Earth blend, I thresholded the grayscale eye image at 0.4 to isolate the pupil/iris geometry. Using full-color Laplacian stacks allows high-frequency skin textures and earth clouds to seam tightly while low-frequency lighting smoothly transitions across the irregular boundary without harsh boundary seams.

Single Most Important Takeaway

The single most important concept I learned from this project is that images are not just static spatial grids of pixels—they are superpositions of spatial frequencies that govern human visual perception. By splitting images into frequency channels using spatial convolutions and Laplacian pyramids, complex tasks like edge detection, image sharpening, seamless texture blending, and distance-based optical illusions become intuitive, elegant matrix operations.